package com.lboyang.seckill.config;

import com.lboyang.seckill.entity.User;

/**
 * @Description
 * @Date 2021/5/31 15:30
 * @Created by: A.iguodala
 */
public class UserContext {

    /**
     * ThreadLocal 保存每个线程的用户
     */
    private static ThreadLocal<User> userHolder = new ThreadLocal<>();

    /**
     * 将user保存进当前线程的ThreadLocal
     * @param user
     */
    public static void setUser(User user) {
        userHolder.set(user);
    }

    public static User getUser() {
        return userHolder.get();
    }

}
